/**
 * <copyright>
 * </copyright>
 *
 */
package de.sabram.upb.specs.con.impl;

import de.sabram.upb.specs.con.ConPackage;
import de.sabram.upb.specs.con.NonTerminal;
import de.sabram.upb.specs.con.RHS;
import de.sabram.upb.specs.con.Rule;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Rule</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.sabram.upb.specs.con.impl.RuleImpl#getNonTerminal <em>Non Terminal</em>}</li>
 *   <li>{@link de.sabram.upb.specs.con.impl.RuleImpl#getRhs <em>Rhs</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RuleImpl extends MinimalEObjectImpl.Container implements Rule
{
  /**
   * The cached value of the '{@link #getNonTerminal() <em>Non Terminal</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getNonTerminal()
   * @generated
   * @ordered
   */
  protected NonTerminal nonTerminal;

  /**
   * The cached value of the '{@link #getRhs() <em>Rhs</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRhs()
   * @generated
   * @ordered
   */
  protected RHS rhs;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected RuleImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return ConPackage.Literals.RULE;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NonTerminal getNonTerminal()
  {
    return nonTerminal;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetNonTerminal(NonTerminal newNonTerminal, NotificationChain msgs)
  {
    NonTerminal oldNonTerminal = nonTerminal;
    nonTerminal = newNonTerminal;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ConPackage.RULE__NON_TERMINAL, oldNonTerminal, newNonTerminal);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setNonTerminal(NonTerminal newNonTerminal)
  {
    if (newNonTerminal != nonTerminal)
    {
      NotificationChain msgs = null;
      if (nonTerminal != null)
        msgs = ((InternalEObject)nonTerminal).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ConPackage.RULE__NON_TERMINAL, null, msgs);
      if (newNonTerminal != null)
        msgs = ((InternalEObject)newNonTerminal).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ConPackage.RULE__NON_TERMINAL, null, msgs);
      msgs = basicSetNonTerminal(newNonTerminal, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ConPackage.RULE__NON_TERMINAL, newNonTerminal, newNonTerminal));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public RHS getRhs()
  {
    return rhs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetRhs(RHS newRhs, NotificationChain msgs)
  {
    RHS oldRhs = rhs;
    rhs = newRhs;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ConPackage.RULE__RHS, oldRhs, newRhs);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRhs(RHS newRhs)
  {
    if (newRhs != rhs)
    {
      NotificationChain msgs = null;
      if (rhs != null)
        msgs = ((InternalEObject)rhs).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ConPackage.RULE__RHS, null, msgs);
      if (newRhs != null)
        msgs = ((InternalEObject)newRhs).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ConPackage.RULE__RHS, null, msgs);
      msgs = basicSetRhs(newRhs, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ConPackage.RULE__RHS, newRhs, newRhs));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case ConPackage.RULE__NON_TERMINAL:
        return basicSetNonTerminal(null, msgs);
      case ConPackage.RULE__RHS:
        return basicSetRhs(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case ConPackage.RULE__NON_TERMINAL:
        return getNonTerminal();
      case ConPackage.RULE__RHS:
        return getRhs();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case ConPackage.RULE__NON_TERMINAL:
        setNonTerminal((NonTerminal)newValue);
        return;
      case ConPackage.RULE__RHS:
        setRhs((RHS)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case ConPackage.RULE__NON_TERMINAL:
        setNonTerminal((NonTerminal)null);
        return;
      case ConPackage.RULE__RHS:
        setRhs((RHS)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case ConPackage.RULE__NON_TERMINAL:
        return nonTerminal != null;
      case ConPackage.RULE__RHS:
        return rhs != null;
    }
    return super.eIsSet(featureID);
  }

} //RuleImpl
